package club.ljwang.controller;

import club.ljwang.constant.MessageConstant;
import club.ljwang.entity.PageResult;
import club.ljwang.entity.QueryPageBean;
import club.ljwang.entity.Result;
import club.ljwang.pojo.CheckGroup;
import club.ljwang.service.CheckGroupService;
import com.alibaba.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Auther: wangl
 * @Date: 2020/2/25 23:06
 * @Description:
 */
@RestController
@RequestMapping("checkgroup")
public class CheckGroupController {

    @Reference
    CheckGroupService checkGroupService;

    @RequestMapping("add")
    public Result add(@RequestBody CheckGroup checkGroup,Integer[] checkitemIds){

        try {
            checkGroupService.add(checkGroup, checkitemIds);
            //新增成功
            return new Result(true, MessageConstant.ADD_CHECKGROUP_SUCCESS);
        } catch (Exception e) {
            //新增失败
            return new Result(false, MessageConstant.ADD_CHECKGROUP_FAIL);
        }


    }

    @RequestMapping("edit")
    public Result edit(@RequestBody CheckGroup checkGroup,Integer[] checkitemIds) {

        try {
            checkGroupService.edit(checkGroup, checkitemIds);
            //新增成功
            return new Result(true, MessageConstant.EDIT_CHECKITEM_SUCCESS);
        } catch (Exception e) {
            //新增失败
            return new Result(false, MessageConstant.EDIT_CHECKGROUP_FAIL);
        }


    }

    @RequestMapping("findPage")
    public PageResult findPage(@RequestBody QueryPageBean queryPageBean) {

        return checkGroupService.findPage(queryPageBean);

    }

    @RequestMapping("findByIdForEdit")
    public Result findByIdForEdit(Integer id) {

        return checkGroupService.findByIdForEdit(id);

    }

    @RequestMapping("findAll")
    public Result findAll() {

        return checkGroupService.findAll();

    }

}
